package com.demo.pojo;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;

public class test {

    public static void main(String[] args) {


       Map<String, Object> map = new HashMap<String, Object>();
        map.put("aaa", 111);
        map.put("bbb", 222);
        map.put("ccc", 333);
        map.put("ddd", 444);
        //Map集合循环遍历方式一
        Object aaa = map.get("aaa");
        System.out.printf("aaa="+aaa.toString());
//            if ("aaa".equals(key)){
//                String value = map.get("aaa").toString();//
//                System.out.println("key:"+key+" vlaue:"+value);
//            }
//            if ("bbb".equals(key)){
//                String value = map.get("bbb").toString();//
//                System.out.println("key:"+key+" vlaue:"+value);
//            }
            //String value = map.get(key).toString();//


 //        int num = 4;
//        for (int i = 0; i <num ; i++) {
//            if (i == num -1){
//                System.out.printf("num="+i);
//            }else {
//                System.out.printf("i="+i);
//            }
//
//        }
        BigDecimal bignum1 = new BigDecimal("10");
        BigDecimal bignum2 = new BigDecimal("5");
        BigDecimal bignum3 = null;

//加法
        bignum3 =  bignum1.add(bignum2);
        System.out.println("和 是：" + bignum3);

//减法
        bignum3 = bignum1.subtract(bignum2);
        System.out.println("差  是：" + bignum3);

//乘法
        bignum3 = bignum1.multiply(bignum2);
        System.out.println("积  是：" + bignum3);

//除法
        bignum3 = bignum1.divide(bignum2);
        System.out.println("商  是：" + bignum3);




        Product prod1 = new Product(1L, 1, new BigDecimal("15.5"), "面包", "零食");
        Product prod2 = new Product(2L, 2, new BigDecimal("20"), "饼干", "零食");
        Product prod3 = new Product(3L, 3, new BigDecimal("30"), "月饼", "零食");
        Product prod4 = new Product(4L, 3, new BigDecimal("10"), "青岛啤酒", "啤酒");
       Product prod5 = new Product(5L, 10, new BigDecimal("15"), "百威啤酒", "啤酒");
        List<Product> list2 = Lists.newArrayList(prod1, prod2, prod3, prod4, prod5);
              List<Product> intersection = list2.stream().filter(item -> item.getNum() >=3).collect(toList());
     List<Product> intersection2 = list2.stream().filter(item -> item.getNum() <=3).collect(toList());

     System.out.println("过滤后的数据 大于等于3的数据" + JSONObject.toJSONString(intersection));
     System.out.println("过滤后的数据其他数据" + JSONObject.toJSONString(intersection2));

//
//        System.out.printf("list2"+list2);
//        String[] arr = new String[] {"面包", "饼干"};
//            List<String> list1 = Arrays.asList(arr);
//            System.out.printf("list1"+list1);
//            // 交集
//
//        List<Product> intersection = list2.stream().filter(item -> !list1.contains(item.getName())).collect(toList());
//
//        //List<String> intersection = list1.stream().filter(item -> !list2.contains(item)).collect(toList());
//            System.out.println("---交集 intersection---");
//            intersection.parallelStream().forEach(System.out :: println);



/*

        Map<String, List<Product>> prodMap= prodList.stream().collect(Collectors.groupingBy(Product::getCategory));

        List<Product> typeOnes = Lists.newArrayList();
        List<Product> type2 = Lists.newArrayList();

        for (Map.Entry<String, List<Product>> entry : prodMap.entrySet()) {
            entry.getKey();
            List<Product> value1 = entry.getValue();
            if ("啤酒".equals(entry.getKey())){
                typeOnes = value1;
              }
            if ("零食".equals(entry.getKey())){
                type2 = value1;
            }

            System.out.println(value1);

        }
        prodMap.forEach((key, value) -> {

//            if ("啤酒".equals(key)){
//                typeOnes.add((Product) value);
//             }

        });
        System.out.println("jihe"+typeOnes);
        System.out.println("jihe2"+type2);
*/

    }
}
